# 3.29 Car Backing Radar ## 3.29.1 Overview When a car is in reverse, it will alarm the distance of the obstacles behind the parking space. In this project, we build a mini car backing radar with an ultrasonic sensor for distance detection, a speaker to alarm, and a traffic light module as an indicator. ## 3.29.2 Test Code ### 3.29.2.1 Code Flow ![6-29-2-1](./media/6-29-2-1.png) ### 3.29.2.2 Build Code There are two ways to upload the code: directly open the code file we provide; or manually build blocks. **Directly open the code file we provide:** 1. Click ![](./media/j68.png) and choose `Load from your computer` ![](./media/j67.png) 2. We have already downloaded the codes on computer desktop, so open the file and choose `3-29-parkingSensor.sb3` **Manually build blocks:** 1. Build the two basic blocks: ![6-1-4-1-1](./media/6-1-4-1-1.png) 2. Declare a variable named *distance* 3. Assign the detected value of the ultrasonic sensor to *distance* ![QQ_1721810318114](./media/6-23-2-2-1.png) 4. Add a ![j25](./media/j25.png) to determine the *distance*. If *distance* > 40, code blocks in it will be executed: the speaker stays quiet, the red LED is off while the green one is ON. ![QQ_1721868975906](./media/6-29-2-2-1.png) 5. Add another ![j25](./media/j25.png). If *distance* < 40, code blocks in it will be executed: the speaker alarms, the red LED is ON while the green one is off. ![QQ_1721870782466](./media/6-29-2-2-2.png) **Complete Test Code** ![6-29-2-2-3](./media/6-29-2-2-3.png) ### 3.29.2.3 Test Result After uploading code, when the the detected distance value is greater than 40cm, the green LED is on and the amplifier does not emit sound. If the value is less than 40cm, the red LED will light up and the amplifier will alarm.